<?php

namespace App\Http\Controllers\Supplier;
use App\Models\MemberPromise;
use App\Services\CommonService;
use Illuminate\Http\Request;

//租赁地址
class LeaseAddressController extends BaseController
{
    //租赁地址列表
    public function leaseAddressList(Request $request)
    {
        $input = $request->input();
        $page = $input['page'] ? $input['page'] : 1;
        $pageSize = $input['pageSize'] ? $input['pageSize'] : CommonService::PAGESIZE;
        $data = MemberPromise::GetLeaseAddressList($pageSize, array('member_id' => $this->shopUser['member_id'], 'is_delete' => MemberPromise::MEMBER_PROMISE_NOT_DELETE));
        $data = formatPage($data);
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS, '获取成功', $data);
    }

    //根据id查询租赁地址
    public function leaseAddressById(Request $request)
    {
        $input = $request->input();
        if (empty($input['id'])) {
            return ReturnMsg(CommonService::HTTP_CODE_FAIL, 'id为空');
        }
        $data = MemberPromise::GetLeaseAddressById($input['id']);
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS, '获取成功', $data);
    }

    //添加或编辑租赁地址
    public function addOrEditLeaseAddress(Request $request)
    {
        $input = $request->input();
        if (empty($input['id'])) { //添加
            $addData = array(
                'member_id' => $this->shopUser['member_id'],
                'province' => $input['province'],
                'city' => $input['city'],
                'area' => $input['area'],
                'address' => $input['address'],
                'promise' => $input['promise'],
                'addtime' => time(),
            );
            $res = MemberPromise::addData($addData);
            if ($res) {
                return ReturnMsg(CommonService::HTTP_CODE_SUCCESS, '添加成功');
            } else {
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '添加失败');
            }
        } else { //编辑
            MemberPromise::editDataById($input['id'], $input);
            return ReturnMsg(CommonService::HTTP_CODE_SUCCESS, '编辑成功');
        }

    }

    //根据id删除租赁地址
    public function delLeaseAddress(Request $request)
    {
        $input = $request->input();
        if (empty($input['id'])) {
            return ReturnMsg(CommonService::HTTP_CODE_FAIL, 'id为空');
        }
        MemberPromise::editDataById($input['id'], array('is_delete' => MemberPromise::MEMBER_PROMISE_IS_DELETE));
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS, '删除成功');
    }


}
